﻿//using System;
//using System.Configuration;
//using System.Data;
//using System.Data.SqlClient;
//using Oracle.DataAccess.Client;
//using TCL.EO;
//using TCL.FUNC;

//namespace TCL.DB
//{
//    public class OracleDataProvider
//    {
//        #region "Properties"
//        public virtual Boolean bWriteLog { get; set; }
//        public virtual String sConnectionStrings { get; set; }
//        #endregion

//        #region DB Access Functions
//        protected void SetConnection(ref OracleCommand cmdOracle)
//        {
//            OracleConnection connOracle = new OracleConnection(ConfigurationManager.ConnectionStrings[sConnectionStrings].ConnectionString);
//            if (connOracle.State != ConnectionState.Open)
//            {
//                connOracle.Open();
//            }
//            cmdOracle.Connection = connOracle;
//        }

//        protected void Convert_SqlCommand_OracleCommand(SqlCommand cmdSql, ref OracleCommand cmdOracle)
//        {
//            cmdOracle.CommandText = cmdSql.CommandText;
//            cmdOracle.CommandType = cmdSql.CommandType;
//            foreach (SqlParameter item in cmdSql.Parameters)
//            {
//                cmdOracle.Parameters.Add(new OracleParameter(item.ParameterName, item.Value));
//            }
//            SetConnection(ref cmdOracle);
//        }

//        public DataSet GetDataSet(SqlCommand cmdSql)
//        {
//            OracleCommand cmdOracle = new OracleCommand();
//            LogDBEO objLog = new LogDBEO(cmdSql, sConnectionStrings, ConstEx.Log_iType.DATABASE_SELECT);
//            try
//            {
//                Convert_SqlCommand_OracleCommand(cmdSql, ref cmdOracle);
//                using (DataSet ds = new DataSet())
//                {
//                    using (OracleDataAdapter da = new OracleDataAdapter())
//                    {
//                        da.SelectCommand = cmdOracle;
//                        da.Fill(ds);
//                        objLog.bStatus = true;
//                        return ds;
//                    }
//                }
//            }
//            finally
//            {
//                cmdOracle.Connection.Close();
//                cmdOracle.Dispose();
//                if (bWriteLog)
//                    (new Logs()).WriteLogDB(objLog);
//            }
//        }

//        public DataTable GetDataTable(SqlCommand cmdSql)
//        {
//            return GetDataSet(cmdSql).Tables[0];
//        }

//        public OracleDataReader GetReadOnlyData(SqlCommand cmdSql)
//        {
//            OracleCommand cmdOracle = new OracleCommand();
//            LogDBEO objLog = new LogDBEO(cmdSql, sConnectionStrings, ConstEx.Log_iType.DATABASE_OTHER);
//            try
//            {
//                Convert_SqlCommand_OracleCommand(cmdSql, ref cmdOracle);
//                objLog.bStatus = true;
//                return cmdOracle.ExecuteReader();
//            }
//            finally
//            {
//                cmdOracle.Connection.Close();
//                cmdOracle.Dispose();
//                if (bWriteLog)
//                    (new Logs()).WriteLogDB(objLog);
//            }
//        }

//        public void ExecuteNonQuery(SqlCommand cmdSql)
//        {
//            OracleCommand cmdOracle = new OracleCommand();
//            LogDBEO objLog = new LogDBEO(cmdSql, sConnectionStrings, ConstEx.Log_iType.DATABASE_INSERT_UPDATE_DELETE);
//            try
//            {
//                Convert_SqlCommand_OracleCommand(cmdSql, ref cmdOracle);
//                cmdOracle.ExecuteNonQuery();
//                objLog.bStatus = true;
//            }
//            finally
//            {
//                cmdOracle.Connection.Close();
//                cmdOracle.Dispose();
//                if (bWriteLog)
//                    (new Logs()).WriteLogDB(objLog);
//            }
//        }

//        public object ExecuteScalar(SqlCommand cmdSql)
//        {
//            OracleCommand cmdOracle = new OracleCommand();
//            LogDBEO objLog = new LogDBEO(cmdSql, sConnectionStrings, ConstEx.Log_iType.DATABASE_OTHER);
//            try
//            {
//                Convert_SqlCommand_OracleCommand(cmdSql, ref cmdOracle);
//                objLog.bStatus = true;
//                return cmdOracle.ExecuteScalar();
//            }
//            finally
//            {
//                cmdOracle.Connection.Close();
//                cmdOracle.Dispose();
//                if (bWriteLog)
//                    (new Logs()).WriteLogDB(objLog);
//            }
//        }
//        #endregion
//    }
//}

////        public int DBSize()
////        {
////            using (OracleCommand cmd = new OracleCommand("select sum(size) * 8 * 1024 from sysfiles"))
////            {
////                cmd.CommandType = CommandType.Text;
////                return (int)ExecuteScalar(cmd);
////            }
////        }

////        public DataTable getDatabaseSizeCurrent(String _DATABASE_NAME)
////        {
////            DataTable dt = new DataTable();
////            OracleCommand cmd = new OracleCommand("getDatabaseSizeCurrent", connOracle);
////            cmd.CommandType = CommandType.StoredProcedure;
////            cmd.Parameters.Add(new SqlParameter("@DATABASE_NAME", _DATABASE_NAME));
////            return GetDataTable(cmd);
////        }

////        public bool CheckConnect()
////        {
////            OracleCommand cmd = new OracleCommand("select getdate()");
////            if (DataTableEx.DataTable_OK(GetDataTable(cmd)))
////                return true;
////            else
////                return false;
////        }

////        public Boolean Backup_Database(String LinkBackup)
////        {
////            OracleCommand cmd = new OracleCommand("BACKUP DATABASE [NguyenManhThang] TO DISK='" + LinkBackup + "'", connOracle);
////            ExecuteNonQuery(cmd);
////            return true;
////        }

////        public Boolean Restore_Database(String LinkRestore)
////        {
////            OracleCommand cmd = new OracleCommand("USE MASTER RESTORE DATABASE [NguyenManhThang] FROM DISK='" + LinkRestore + "'", connOracle);
////            ExecuteNonQuery(cmd);
////            return true;
////        }
